#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_N 10000
#define MAX_V 10000

int dp[MAX_N + 5][MAX_V + 5];
int v[MAX_N + 5], c[MAX_N + 5];

int main()
{
    int n, V;
    cin >> n >> V;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i] >> c[i];
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= V; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if(j < v[i]) continue;
            dp[i][j] = max(dp[i][j], dp[i][j - v[i]] + c[i]);
        }
    }
    std::cout << dp[n][V] << std::endl;
    return 0;
}